package com.dc.seckill.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @模块 redis缓存模块
 * @作者 djs
 * @时间 2018/3/20 8:38
 * @版本 V1.0
 * @描述 redis工厂类，获取redis连接池
 */
@Service
public class RedisFactory {

    @Autowired
    RedisConfig redisConfig;

    @Bean
    public JedisPool getJedisPoolFactory(){

        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(redisConfig.getPoolMaxIdle());
        poolConfig.setMaxTotal(redisConfig.getPoolMaxTotal());
        poolConfig.setMaxWaitMillis(redisConfig.getPoolMaxWait()*1000);
        JedisPool jp = new JedisPool(poolConfig, redisConfig.getHost(), redisConfig.getPort(),
                redisConfig.getTimeout()*1000, redisConfig.getPassword());
        return jp;
    }

}
